

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>pymunk &mdash; pymunk 4.0.0 documentation</title>
    
    <link rel="stylesheet" href="../_static/pymunk.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '4.0.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="shortcut icon" href="../_static/pymunk_favicon.ico"/>
    <link rel="top" title="pymunk 4.0.0 documentation" href="../index.html" />
    <link rel="up" title="Module code" href="index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../index.html">pymunk 4.0.0 documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for pymunk</h1><div class="highlight"><pre>
<span class="c"># ----------------------------------------------------------------------------</span>
<span class="c"># pymunk</span>
<span class="c"># Copyright (c) 2007-2012 Victor Blomqvist</span>
<span class="c">#</span>
<span class="c"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c"># in the Software without restriction, including without limitation the rights</span>
<span class="c"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c"># furnished to do so, subject to the following conditions:</span>
<span class="c">#</span>
<span class="c"># The above copyright notice and this permission notice shall be included in</span>
<span class="c"># all copies or substantial portions of the Software.</span>
<span class="c">#</span>
<span class="c"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<span class="c"># SOFTWARE.</span>
<span class="c"># ----------------------------------------------------------------------------</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">pymunk is a easy-to-use pythonic 2d physics library that can be used whenever </span>
<span class="sd">you need 2d rigid body physics from Python.</span>

<span class="sd">Homepage: http://www.pymunk.org</span>

<span class="sd">This is the main containing module of pymunk. It contains among other things </span>
<span class="sd">the very central Space, Body and Shape classes.</span>

<span class="sd">When you import this module it will automatically load the chipmunk library </span>
<span class="sd">file. As long as you haven&#39;t turned off the debug mode a print will show </span>
<span class="sd">exactly which Chipmunk library file it loaded. For example::</span>

<span class="sd">    &gt;&gt;&gt; import pymunk</span>
<span class="sd">    Loading chipmunk for Windows (32bit) [C:\code\pymunk\chipmunk.dll]</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s">&quot;$Id: __init__.py 527 2013-08-20 17:05:25Z vb@viblo.se $&quot;</span>
<span class="n">__docformat__</span> <span class="o">=</span> <span class="s">&quot;reStructuredText&quot;</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s">&quot;inf&quot;</span><span class="p">,</span> <span class="s">&quot;version&quot;</span><span class="p">,</span> <span class="s">&quot;chipmunk_version&quot;</span>
        <span class="p">,</span> <span class="s">&quot;Space&quot;</span><span class="p">,</span> <span class="s">&quot;Body&quot;</span><span class="p">,</span> <span class="s">&quot;Shape&quot;</span><span class="p">,</span> <span class="s">&quot;Circle&quot;</span><span class="p">,</span> <span class="s">&quot;Poly&quot;</span><span class="p">,</span> <span class="s">&quot;Segment&quot;</span>
        <span class="p">,</span> <span class="s">&quot;moment_for_circle&quot;</span><span class="p">,</span> <span class="s">&quot;moment_for_poly&quot;</span><span class="p">,</span> <span class="s">&quot;moment_for_segment&quot;</span>
        <span class="p">,</span> <span class="s">&quot;moment_for_box&quot;</span><span class="p">,</span> <span class="s">&quot;reset_shapeid_counter&quot;</span>
        <span class="p">,</span> <span class="s">&quot;SegmentQueryInfo&quot;</span><span class="p">,</span> <span class="s">&quot;Contact&quot;</span><span class="p">,</span> <span class="s">&quot;Arbiter&quot;</span><span class="p">,</span> <span class="s">&quot;BB&quot;</span><span class="p">]</span>

<span class="kn">import</span> <span class="nn">ctypes</span> <span class="kn">as</span> <span class="nn">ct</span>
<span class="kn">import</span> <span class="nn">weakref</span>

<span class="k">try</span><span class="p">:</span>
    <span class="c">#Python 2.7+ </span>
    <span class="kn">from</span> <span class="nn">weakref</span> <span class="kn">import</span> <span class="n">WeakSet</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">.weakrefset</span> <span class="kn">import</span> <span class="n">WeakSet</span>

<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">_chipmunk</span> <span class="k">as</span> <span class="n">cp</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">_chipmunk_ffi</span> <span class="k">as</span> <span class="n">cpffi</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">util</span> <span class="k">as</span> <span class="n">u</span>
<span class="kn">from</span> <span class="nn">.vec2d</span> <span class="kn">import</span> <span class="n">Vec2d</span>

<span class="kn">from</span> <span class="nn">pymunk.constraint</span> <span class="kn">import</span> <span class="o">*</span>

<span class="n">version</span> <span class="o">=</span> <span class="s">&quot;4.0.0&quot;</span>
<span class="sd">&quot;&quot;&quot;The release version of this pymunk installation.</span>
<span class="sd">Valid only if pymunk was installed from a source or binary </span>
<span class="sd">distribution (i.e. not in a checked-out copy from svn).</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="n">chipmunk_version</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">R</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpVersionString</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">decode</span><span class="p">(),</span> <span class="s">&#39;3bdf1b7b3c&#39;</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;The Chipmunk version compatible with this pymunk version.</span>
<span class="sd">Other (newer) Chipmunk versions might also work if the new version does not </span>
<span class="sd">contain any breaking API changes.</span>

<span class="sd">This property does not show a valid value in the compiled documentation, only </span>
<span class="sd">when you actually import pymunk and do pymunk.chipmunk_version</span>

<span class="sd">The string is in the following format:</span>
<span class="sd">&lt;cpVersionString&gt;R&lt;svn or github commit of chipmunk&gt;</span>
<span class="sd">where cpVersionString is a version string set by Chipmunk and the svn version </span>
<span class="sd">corresponds to the svn version of the chipmunk source files included with </span>
<span class="sd">pymunk or the github commit hash. If the Chipmunk version is a release then </span>
<span class="sd">the second part will be empty</span>

<span class="sd">.. note:: </span>
<span class="sd">    This is also the version of the Chipmunk source files included in the </span>
<span class="sd">    chipmunk_src folder (normally included in the pymunk source distribution).</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="c">#inf = float(&#39;inf&#39;) # works only on python 2.6+</span>
<span class="n">inf</span> <span class="o">=</span> <span class="mf">1e100</span>
<span class="sd">&quot;&quot;&quot;Infinity that can be passed as mass or inertia to Body. </span>

<span class="sd">Useful when you for example want a body that cannot rotate, just set its </span>
<span class="sd">moment to inf. Just remember that if two objects with both infinite masses </span>
<span class="sd">collides the world might explode. Similary effects can happen with infinite </span>
<span class="sd">moment.</span>

<span class="sd">.. note::</span>
<span class="sd">    In previous versions of pymunk you used inf to create static bodies. This</span>
<span class="sd">    has changed and you should instead do it by invoking the body constructor </span>
<span class="sd">    without any arguments.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="n">cp</span><span class="o">.</span><span class="n">cpEnableSegmentToSegmentCollisions</span><span class="p">()</span>

<div class="viewcode-block" id="Space"><a class="viewcode-back" href="../pymunk.html#pymunk.Space">[docs]</a><span class="k">class</span> <span class="nc">Space</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Spaces are the basic unit of simulation. You add rigid bodies, shapes </span>
<span class="sd">    and joints to it and then step them all forward together through time. </span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Space.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iterations</span><span class="o">=</span><span class="mi">10</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Create a new instace of the Space</span>
<span class="sd">        </span>
<span class="sd">        Its usually best to keep the elastic_iterations setting to 0. Only </span>
<span class="sd">        change if you have problem with stacking elastic objects on each other. </span>
<span class="sd">        If that is the case, try to raise it. However, a value other than 0 </span>
<span class="sd">        will affect other parts, most importantly you wont get reliable </span>
<span class="sd">        total_impulse readings from the `Arbiter` object in collsion callbacks!</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            iterations : int</span>
<span class="sd">                Number of iterations to use in the impulse solver to solve </span>
<span class="sd">                contacts.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceNew</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">iterations</span> <span class="o">=</span> <span class="n">iterations</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_static_body</span> <span class="o">=</span> <span class="n">Body</span><span class="p">()</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_handlers</span> <span class="o">=</span> <span class="p">{}</span> <span class="c"># To prevent the gc to collect the callbacks.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_default_handler</span> <span class="o">=</span> <span class="bp">None</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_post_step_callbacks</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_post_callback_keys</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_post_last_callback_key</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_removed_shapes</span> <span class="o">=</span> <span class="p">{}</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapes</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodies</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_locked</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_add_later</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_remove_later</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
</div>
    <span class="k">def</span> <span class="nf">_get_shapes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shapes</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
    <span class="n">shapes</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_shapes</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;A list of all the shapes added to this space (both static and non-static)&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_bodies</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bodies</span><span class="p">)</span>
    <span class="n">bodies</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_bodies</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;A list of the bodies added to this space&quot;&quot;&quot;</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_get_constraints</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span><span class="p">)</span>
    <span class="n">constraints</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_constraints</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;A list of the constraints added to this space&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_static_body</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;A convenience static body already added to the space&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_static_body</span>
    <span class="n">static_body</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_static_body</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="n">_get_static_body</span><span class="o">.</span><span class="n">__doc__</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceFree</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">)</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_iterations</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iterations</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">iterations</span> <span class="o">=</span> <span class="n">iterations</span>
    <span class="k">def</span> <span class="nf">_get_iterations</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">iterations</span>
    <span class="n">iterations</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_iterations</span><span class="p">,</span> <span class="n">_set_iterations</span>
        <span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Number of iterations to use in the impulse solver to solve </span>
<span class="s">        contacts.&quot;&quot;&quot;</span><span class="p">)</span>

            
    <span class="k">def</span> <span class="nf">_set_gravity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">gravity_vec</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">gravity</span> <span class="o">=</span> <span class="n">gravity_vec</span>
    <span class="k">def</span> <span class="nf">_get_gravity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">gravity</span>
    <span class="n">gravity</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_gravity</span><span class="p">,</span> <span class="n">_set_gravity</span>
        <span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Default gravity to supply when integrating rigid body motions.&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_damping</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">damping</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">damping</span> <span class="o">=</span> <span class="n">damping</span>
    <span class="k">def</span> <span class="nf">_get_damping</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">damping</span>
    <span class="n">damping</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_damping</span><span class="p">,</span> <span class="n">_set_damping</span>
        <span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Damping rate expressed as the fraction of velocity bodies </span>
<span class="s">        retain each second.</span>
<span class="s">        </span>
<span class="s">        A value of 0.9 would mean that each body&#39;s velocity will drop 10% per </span>
<span class="s">        second. The default value is 1.0, meaning no damping is applied.&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_idle_speed_threshold</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">idle_speed_threshold</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">idleSpeedThreshold</span> <span class="o">=</span> <span class="n">idle_speed_threshold</span>
    <span class="k">def</span> <span class="nf">_get_idle_speed_threshold</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">idleSpeedThreshold</span>
    <span class="n">idle_speed_threshold</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_idle_speed_threshold</span>
        <span class="p">,</span> <span class="n">_set_idle_speed_threshold</span>
        <span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Speed threshold for a body to be considered idle.</span>
<span class="s">        The default value of 0 means to let the space guess a good threshold </span>
<span class="s">        based on gravity.&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_sleep_time_threshold</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sleep_time_threshold</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">sleepTimeThreshold</span> <span class="o">=</span> <span class="n">sleep_time_threshold</span>
    <span class="k">def</span> <span class="nf">_get_sleep_time_threshold</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">sleepTimeThreshold</span>
    <span class="n">sleep_time_threshold</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_sleep_time_threshold</span>
        <span class="p">,</span> <span class="n">_set_sleep_time_threshold</span>
        <span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Time a group of bodies must remain idle in order to fall </span>
<span class="s">        asleep.</span>
<span class="s">        </span>
<span class="s">        Enabling sleeping also implicitly enables the the contact graph. The </span>
<span class="s">        default value of `inf` disables the sleeping algorithm.&quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_set_collision_slop</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">collision_slop</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">collisionSlop</span> <span class="o">=</span> <span class="n">collision_slop</span>
    <span class="k">def</span> <span class="nf">_get_collision_slop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">collisionSlop</span>
    <span class="n">collision_slop</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_collision_slop</span>
        <span class="p">,</span> <span class="n">_set_collision_slop</span>
        <span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Amount of allowed penetration.</span>
<span class="s">        </span>
<span class="s">        Used to reduce oscillating contacts and keep the collision cache warm. </span>
<span class="s">        Defaults to 0.1. If you have poor simulation quality, increase this </span>
<span class="s">        number as much as possible without allowing visible amounts of </span>
<span class="s">        overlap.&quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_set_collision_bias</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">collision_bias</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">collisionBias</span> <span class="o">=</span> <span class="n">collision_bias</span>
    <span class="k">def</span> <span class="nf">_get_collision_bias</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">collisionBias</span>
    <span class="n">collision_bias</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_collision_bias</span>
        <span class="p">,</span> <span class="n">_set_collision_bias</span>
        <span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Determines how fast overlapping shapes are pushed apart.</span>
<span class="s">        </span>
<span class="s">        Expressed as a fraction of the error remaining after each second. </span>
<span class="s">        Defaults to pow(1.0 - 0.1, 60.0) meaning that pymunk fixes 10</span><span class="si">% o</span><span class="s">f </span>
<span class="s">        overlap each frame at 60Hz.&quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_set_collision_persistence</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">collision_persistence</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">collisionPersistence</span> <span class="o">=</span> <span class="n">collision_persistence</span>
    <span class="k">def</span> <span class="nf">_get_collision_persistence</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">collisionPersistence</span>
    <span class="n">collision_persistence</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_collision_persistence</span>
        <span class="p">,</span> <span class="n">_set_collision_persistence</span>
        <span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Number of frames that contact information should persist.</span>
<span class="s">        </span>
<span class="s">        Defaults to 3. There is probably never a reason to change this value.</span>
<span class="s">        &quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_set_enable_contact_graph</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">enable_contact_graph</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">enableContactGraph</span> <span class="o">=</span> <span class="n">enable_contact_graph</span>
    <span class="k">def</span> <span class="nf">_get_enable_contact_graph</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">enableContactGraph</span> 
    <span class="n">enable_contact_graph</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_enable_contact_graph</span>
        <span class="p">,</span> <span class="n">_set_enable_contact_graph</span>
        <span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Rebuild the contact graph during each step. </span>
<span class="s">        </span>
<span class="s">        Must be enabled to use the get_arbiter() function on Body</span>
<span class="s">        Disabled by default for a small performance boost. Enabled implicitly </span>
<span class="s">        when the sleeping feature is enabled.</span>
<span class="s">        &quot;&quot;&quot;</span><span class="p">)</span>
        
<div class="viewcode-block" id="Space.add"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.add">[docs]</a>    <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">objs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add one or many shapes, bodies or joints to the space</span>
<span class="sd">        </span>
<span class="sd">        Unlike Chipmunk and earlier versions of pymunk its now allowed to add </span>
<span class="sd">        objects even from a callback during the simulation step. However, the </span>
<span class="sd">        add will not be performed until the end of the step.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_locked</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_add_later</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">objs</span><span class="p">)</span>
            <span class="k">return</span>
            
        <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">objs</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">Body</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_add_body</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">Shape</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_add_shape</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">Constraint</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_add_constraint</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">oo</span> <span class="ow">in</span> <span class="n">o</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">oo</span><span class="p">)</span>
                    </div>
<div class="viewcode-block" id="Space.remove"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.remove">[docs]</a>    <span class="k">def</span> <span class="nf">remove</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">objs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Remove one or many shapes, bodies or constraints from the space</span>
<span class="sd">        </span>
<span class="sd">        Unlike Chipmunk and earlier versions of pymunk its now allowed to </span>
<span class="sd">        remove objects even from a callback during the simulation step. </span>
<span class="sd">        However, the removal will not be performed until the end of the step.</span>
<span class="sd">        </span>
<span class="sd">        .. Note:: </span>
<span class="sd">            When removing objects from the space, make sure you remove any </span>
<span class="sd">            other objects that reference it. For instance, when you remove a </span>
<span class="sd">            body, remove the joints and shapes attached to it. </span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_locked</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_remove_later</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">objs</span><span class="p">)</span>
            <span class="k">return</span>
            
        <span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">objs</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">Body</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_remove_body</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">Shape</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_remove_shape</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">Constraint</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_remove_constraint</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">oo</span> <span class="ow">in</span> <span class="n">o</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">oo</span><span class="p">)</span>
                                        </div>
    <span class="k">def</span> <span class="nf">_add_shape</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">shape</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Adds a shape to the space&quot;&quot;&quot;</span>
        <span class="k">assert</span> <span class="n">shape</span><span class="o">.</span><span class="n">_hashid_private</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapes</span><span class="p">,</span> <span class="s">&quot;shape already added to space&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapes</span><span class="p">[</span><span class="n">shape</span><span class="o">.</span><span class="n">_hashid_private</span><span class="p">]</span> <span class="o">=</span> <span class="n">shape</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceAddShape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">shape</span><span class="o">.</span><span class="n">_shape</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">_add_body</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">body</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Adds a body to the space&quot;&quot;&quot;</span>
        <span class="k">assert</span> <span class="n">body</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodies</span><span class="p">,</span> <span class="s">&quot;body already added to space&quot;</span>
        <span class="n">body</span><span class="o">.</span><span class="n">_space</span> <span class="o">=</span> <span class="n">weakref</span><span class="o">.</span><span class="n">proxy</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodies</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceAddBody</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">body</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">_add_constraint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">constraint</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Adds a constraint to the space&quot;&quot;&quot;</span>
        <span class="k">assert</span> <span class="n">constraint</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span><span class="p">,</span> <span class="s">&quot;constraint already added to space&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">constraint</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceAddConstraint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">constraint</span><span class="o">.</span><span class="n">_constraint</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_remove_shape</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">shape</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Removes a shape from the space&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_removed_shapes</span><span class="p">[</span><span class="n">shape</span><span class="o">.</span><span class="n">_hashid_private</span><span class="p">]</span> <span class="o">=</span> <span class="n">shape</span>
        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapes</span><span class="p">[</span><span class="n">shape</span><span class="o">.</span><span class="n">_hashid_private</span><span class="p">]</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceRemoveShape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">shape</span><span class="o">.</span><span class="n">_shape</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">_remove_body</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">body</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Removes a body from the space&quot;&quot;&quot;</span>
        <span class="n">body</span><span class="o">.</span><span class="n">_space</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodies</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceRemoveBody</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">body</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">_remove_constraint</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">constraint</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Removes a constraint from the space&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">constraint</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceRemoveConstraint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">constraint</span><span class="o">.</span><span class="n">_constraint</span><span class="p">)</span>

<div class="viewcode-block" id="Space.reindex_static"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.reindex_static">[docs]</a>    <span class="k">def</span> <span class="nf">reindex_static</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Update the collision detection info for the static shapes in the </span>
<span class="sd">        space. You only need to call this if you move one of the static shapes.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceReindexStatic</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Space.reindex_shape"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.reindex_shape">[docs]</a>    <span class="k">def</span> <span class="nf">reindex_shape</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">shape</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Update the collision detection data for a specific shape in the </span>
<span class="sd">        space.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceReindexShape</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">shape</span><span class="o">.</span><span class="n">_shape</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="Space.step"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.step">[docs]</a>    <span class="k">def</span> <span class="nf">step</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dt</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Update the space for the given time step. Using a fixed time step is</span>
<span class="sd">        highly recommended. Doing so will increase the efficiency of the</span>
<span class="sd">        contact persistence, requiring an order of magnitude fewer iterations</span>
<span class="sd">        to resolve the collisions in the usual case.&quot;&quot;&quot;</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_locked</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceStep</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_removed_shapes</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_post_step_callbacks</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_post_callback_keys</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_post_last_callback_key</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_locked</span> <span class="o">=</span> <span class="bp">False</span>
        
        <span class="k">for</span> <span class="n">objs</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_add_later</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">objs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_add_later</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        
        <span class="k">for</span> <span class="n">objs</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_remove_later</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">objs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_remove_later</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
    </div>
<div class="viewcode-block" id="Space.add_collision_handler"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.add_collision_handler">[docs]</a>    <span class="k">def</span> <span class="nf">add_collision_handler</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">begin</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">pre_solve</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">post_solve</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">separate</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a collision handler for given collision type pair. </span>
<span class="sd">        </span>
<span class="sd">        Whenever a shapes with collision_type a and collision_type b collide, </span>
<span class="sd">        these callbacks will be used to process the collision. </span>
<span class="sd">        None can be provided for callbacks you do not wish to implement, </span>
<span class="sd">        however pymunk will call it&#39;s own default versions for these and not </span>
<span class="sd">        the default ones you&#39;ve set up for the Space. If you need to fall back </span>
<span class="sd">        on the space&#39;s default callbacks, you&#39;ll have to provide them </span>
<span class="sd">        individually to each handler definition.</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            a : int</span>
<span class="sd">                Collision type of the first shape</span>
<span class="sd">            b : int </span>
<span class="sd">                Collision type of the second shape</span>
<span class="sd">            begin : ``func(space, arbiter, *args, **kwargs) -&gt; bool``</span>
<span class="sd">                Collision handler called when two shapes just started touching </span>
<span class="sd">                for the first time this step. Return false from the callback </span>
<span class="sd">                to make pymunk ignore the collision or true to process it </span>
<span class="sd">                normally. Rejecting a collision from a begin() callback </span>
<span class="sd">                permanently rejects the collision until separation. Pass </span>
<span class="sd">                `None` if you wish to use the pymunk default.</span>
<span class="sd">            pre_solve : ``func(space, arbiter, *args, **kwargs) -&gt; bool``</span>
<span class="sd">                Collision handler called when two shapes are touching. Return </span>
<span class="sd">                false from the callback to make pymunk ignore the collision or </span>
<span class="sd">                true to process it normally. Additionally, you may override </span>
<span class="sd">                collision values such as `Arbiter.elasticity` and </span>
<span class="sd">                `Arbiter.friction` to provide custom friction or elasticity </span>
<span class="sd">                values. See `Arbiter` for more info. Pass `None` if you wish </span>
<span class="sd">                to use the pymunk default.</span>
<span class="sd">            post_solve : ``func(space, arbiter, *args, **kwargs)``</span>
<span class="sd">                Collsion handler called when two shapes are touching and their </span>
<span class="sd">                collision response has been processed. You can retrieve the </span>
<span class="sd">                collision force at this time if you want to use it to </span>
<span class="sd">                calculate sound volumes or damage amounts. Pass `None` if you </span>
<span class="sd">                wish to use the pymunk default.</span>
<span class="sd">            separate : ``func(space, arbiter, *args, **kwargs)``</span>
<span class="sd">                Collision handler called when two shapes have just stopped </span>
<span class="sd">                touching for the first time this frame. Pass `None` if you </span>
<span class="sd">                wish to use the pymunk default.</span>
<span class="sd">            args</span>
<span class="sd">                Optional parameters passed to the collision handler functions.</span>
<span class="sd">            kwargs</span>
<span class="sd">                Optional keyword parameters passed on to the collision handler </span>
<span class="sd">                functions.</span>
<span class="sd">                </span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="n">_functions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_collision_function_helper</span><span class="p">(</span><span class="n">begin</span><span class="p">,</span> <span class="n">pre_solve</span><span class="p">,</span> <span class="n">post_solve</span><span class="p">,</span> <span class="n">separate</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_handlers</span><span class="p">[(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)]</span> <span class="o">=</span> <span class="n">_functions</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceAddCollisionHandler</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> 
            <span class="n">_functions</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">_functions</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">_functions</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">_functions</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="bp">None</span><span class="p">)</span>
            </div>
<div class="viewcode-block" id="Space.set_default_collision_handler"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.set_default_collision_handler">[docs]</a>    <span class="k">def</span> <span class="nf">set_default_collision_handler</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">begin</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">pre_solve</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">post_solve</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">separate</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Register a default collision handler to be used when no specific </span>
<span class="sd">        collision handler is found. If you do nothing, the space will be given </span>
<span class="sd">        a default handler that accepts all collisions in begin() and </span>
<span class="sd">        pre_solve() and does nothing for the post_solve() and separate() </span>
<span class="sd">        callbacks. </span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            begin : ``func(space, arbiter, *args, **kwargs) -&gt; bool``</span>
<span class="sd">                Collision handler called when two shapes just started touching </span>
<span class="sd">                for the first time this step. Return False from the callback </span>
<span class="sd">                to make pymunk ignore the collision or True to process it </span>
<span class="sd">                normally. Rejecting a collision from a begin() callback </span>
<span class="sd">                permanently rejects the collision until separation. Pass </span>
<span class="sd">                `None` if you wish to use the pymunk default.</span>
<span class="sd">            pre_solve : ``func(space, arbiter, *args, **kwargs) -&gt; bool``</span>
<span class="sd">                Collision handler called when two shapes are touching. Return </span>
<span class="sd">                False from the callback to make pymunk ignore the collision or </span>
<span class="sd">                True to process it normally. Additionally, you may override </span>
<span class="sd">                collision values such as Arbiter.elasticity and </span>
<span class="sd">                Arbiter.friction to provide custom friction or elasticity </span>
<span class="sd">                values. See Arbiter for more info. Pass `None` if you wish to </span>
<span class="sd">                use the pymunk default.</span>
<span class="sd">            post_solve : ``func(space, arbiter, *args, **kwargs)``</span>
<span class="sd">                Collsion handler called when two shapes are touching and their </span>
<span class="sd">                collision response has been processed. You can retrieve the </span>
<span class="sd">                collision force at this time if you want to use it to </span>
<span class="sd">                calculate sound volumes or damage amounts. Pass `None` if you </span>
<span class="sd">                wish to use the pymunk default.</span>
<span class="sd">            separate : ``func(space, arbiter, *args, **kwargs)``</span>
<span class="sd">                Collision handler called when two shapes have just stopped </span>
<span class="sd">                touching for the first time this frame. Pass `None` if you wish </span>
<span class="sd">                to use the pymunk default.</span>
<span class="sd">            args</span>
<span class="sd">                Optional parameters passed to the collision handler functions.</span>
<span class="sd">            kwargs</span>
<span class="sd">                Optional keyword parameters passed on to the collision handler </span>
<span class="sd">                functions.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="n">_functions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_collision_function_helper</span><span class="p">(</span>
            <span class="n">begin</span><span class="p">,</span> <span class="n">pre_solve</span><span class="p">,</span> <span class="n">post_solve</span><span class="p">,</span> <span class="n">separate</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span>
            <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_default_handler</span> <span class="o">=</span> <span class="n">_functions</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceSetDefaultCollisionHandler</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span>
            <span class="n">_functions</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">_functions</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">_functions</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">_functions</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="bp">None</span><span class="p">)</span>
    </div>
    <span class="k">def</span> <span class="nf">_collision_function_helper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">begin</span><span class="p">,</span> <span class="n">pre_solve</span><span class="p">,</span> <span class="n">post_solve</span><span class="p">,</span> <span class="n">separate</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        
        <span class="n">functions</span> <span class="o">=</span> <span class="p">[(</span><span class="n">begin</span><span class="p">,</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpCollisionBeginFunc</span><span class="p">)</span>
                    <span class="p">,</span> <span class="p">(</span><span class="n">pre_solve</span><span class="p">,</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpCollisionPreSolveFunc</span><span class="p">)</span>
                    <span class="p">,</span> <span class="p">(</span><span class="n">post_solve</span><span class="p">,</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpCollisionPostSolveFunc</span><span class="p">)</span>
                    <span class="p">,</span> <span class="p">(</span><span class="n">separate</span><span class="p">,</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpCollisionSeparateFunc</span><span class="p">)]</span>
        
        <span class="n">_functions</span> <span class="o">=</span> <span class="p">[]</span>
        
        <span class="k">for</span> <span class="n">func</span><span class="p">,</span> <span class="n">func_type</span> <span class="ow">in</span> <span class="n">functions</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">func</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">_f</span> <span class="o">=</span> <span class="n">ct</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">ct</span><span class="o">.</span><span class="n">c_int</span><span class="p">)(),</span> <span class="n">func_type</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">_f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_cf1</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">func_type</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="n">_functions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_f</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">_functions</span>
    
<div class="viewcode-block" id="Space.remove_collision_handler"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.remove_collision_handler">[docs]</a>    <span class="k">def</span> <span class="nf">remove_collision_handler</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Remove a collision handler for a given collision type pair.</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            a : int</span>
<span class="sd">                Collision type of the first shape</span>
<span class="sd">            b : int</span>
<span class="sd">                Collision type of the second shape</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_handlers</span><span class="p">:</span>
            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_handlers</span><span class="p">[(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)]</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceRemoveCollisionHandler</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
        
    </div>
    <span class="k">def</span> <span class="nf">_get_cf1</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="n">function_type</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">def</span> <span class="nf">cf</span><span class="p">(</span><span class="n">_arbiter</span><span class="p">,</span> <span class="n">_space</span><span class="p">,</span> <span class="n">_data</span><span class="p">):</span>
            <span class="n">arbiter</span> <span class="o">=</span> <span class="n">Arbiter</span><span class="p">(</span><span class="n">_arbiter</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">arbiter</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">function_type</span><span class="p">(</span><span class="n">cf</span><span class="p">)</span>
        
    
<div class="viewcode-block" id="Space.add_post_step_callback"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.add_post_step_callback">[docs]</a>    <span class="k">def</span> <span class="nf">add_post_step_callback</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">callback_function</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a function to be called last in the next simulation step.</span>
<span class="sd">                </span>
<span class="sd">        Post step callbacks are registered as a function and an object used as </span>
<span class="sd">        a key. You can only register one post step callback per object. </span>
<span class="sd">        </span>
<span class="sd">        This function was more useful with earlier versions of pymunk where </span>
<span class="sd">        you weren&#39;t allowed to use the add and remove methods on the space </span>
<span class="sd">        during a simulation step. But this function is still available for </span>
<span class="sd">        other uses and to keep backwards compatibility. </span>
<span class="sd">        </span>
<span class="sd">        .. Note::</span>
<span class="sd">            If you remove a shape from the callback it will trigger the</span>
<span class="sd">            collision handler for the &#39;separate&#39; event if it the shape was </span>
<span class="sd">            touching when removed.</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            callback_function : ``func(obj, *args, **kwargs)``</span>
<span class="sd">                The callback function.</span>
<span class="sd">            obj : Any object</span>
<span class="sd">                This object is used as a key, you can only have one callback </span>
<span class="sd">                for a single object. It is passed on to the callback function.</span>
<span class="sd">            args</span>
<span class="sd">                Optional parameters passed to the callback function.</span>
<span class="sd">            kwargs</span>
<span class="sd">                Optional keyword parameters passed on to the callback function.</span>
<span class="sd">                </span>
<span class="sd">        :Return: </span>
<span class="sd">            True if key was not previously added, False otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="k">if</span> <span class="n">obj</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_post_callback_keys</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">False</span>
            
        <span class="k">def</span> <span class="nf">cf</span><span class="p">(</span><span class="n">_space</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
            <span class="n">callback_function</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            
        <span class="n">f</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpPostStepFunc</span><span class="p">(</span><span class="n">cf</span><span class="p">)</span>
                
        <span class="bp">self</span><span class="o">.</span><span class="n">_post_last_callback_key</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_post_callback_keys</span><span class="p">[</span><span class="n">obj</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_post_last_callback_key</span>    
        <span class="bp">self</span><span class="o">.</span><span class="n">_post_step_callbacks</span><span class="p">[</span><span class="n">obj</span><span class="p">]</span> <span class="o">=</span> <span class="n">f</span>
        
        <span class="n">key</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_post_callback_keys</span><span class="p">[</span><span class="n">obj</span><span class="p">]</span>
        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceAddPostStepCallback</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="bp">None</span><span class="p">))</span>
                </div>
<div class="viewcode-block" id="Space.point_query"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.point_query">[docs]</a>    <span class="k">def</span> <span class="nf">point_query</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">layers</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Query space at point filtering out matches with the given layers </span>
<span class="sd">        and group. Return a list of found shapes.</span>
<span class="sd">        </span>
<span class="sd">        If you don&#39;t want to filter out any matches, use -1 for the layers </span>
<span class="sd">        and 0 as the group.</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:    </span>
<span class="sd">            point : (x,y) or `Vec2d`</span>
<span class="sd">                Define where to check for collision in the space.</span>
<span class="sd">            layers : int</span>
<span class="sd">                Only pick shapes matching the bit mask. i.e. </span>
<span class="sd">                (layers &amp; shape.layers) != 0</span>
<span class="sd">            group : int</span>
<span class="sd">                Only pick shapes not in this group.</span>
<span class="sd">                </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">def</span> <span class="nf">cf</span><span class="p">(</span><span class="n">_shape</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
            <span class="n">shape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">_shape</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">shape</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSpacePointQueryFunc</span><span class="p">(</span><span class="n">cf</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpacePointQuery</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">layers</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span>
    </div>
<div class="viewcode-block" id="Space.point_query_first"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.point_query_first">[docs]</a>    <span class="k">def</span> <span class="nf">point_query_first</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">layers</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Query space at point and return the first shape found matching the </span>
<span class="sd">        given layers and group. Returns None if no shape was found.</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:    </span>
<span class="sd">            point : (x,y) or `Vec2d`</span>
<span class="sd">                Define where to check for collision in the space.</span>
<span class="sd">            layers : int</span>
<span class="sd">                Only pick shapes matching the bit mask. i.e. </span>
<span class="sd">                (layers &amp; shape.layers) != 0</span>
<span class="sd">            group : int</span>
<span class="sd">                Only pick shapes not in this group.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">_shape</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSpacePointQueryFirst</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">layers</span><span class="p">,</span> <span class="n">group</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">_shape</span><span class="p">)</span>
        </div>
    <span class="k">def</span> <span class="nf">_get_shape</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">_shape</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">bool</span><span class="p">(</span><span class="n">_shape</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">None</span>
        <span class="n">hashid_private</span> <span class="o">=</span> <span class="n">_shape</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">hashid_private</span>
        <span class="c">#return self._shapes[hashid_private]  </span>
        <span class="k">if</span> <span class="n">hashid_private</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapes</span><span class="p">:</span>
            <span class="n">shape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapes</span><span class="p">[</span><span class="n">hashid_private</span><span class="p">]</span>        
        <span class="k">elif</span> <span class="n">hashid_private</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_removed_shapes</span><span class="p">:</span>
            <span class="n">shape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_removed_shapes</span><span class="p">[</span><span class="n">hashid_private</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">shape</span>
        
<div class="viewcode-block" id="Space.nearest_point_query"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.nearest_point_query">[docs]</a>    <span class="k">def</span> <span class="nf">nearest_point_query</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">max_distance</span><span class="p">,</span> <span class="n">layers</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Query space at point filtering out matches with the given layers </span>
<span class="sd">        and group. Return a list of all shapes within max_distance of the point.</span>
<span class="sd">        </span>
<span class="sd">        If you don&#39;t want to filter out any matches, use -1 for the layers </span>
<span class="sd">        and 0 as the group.</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:    </span>
<span class="sd">            point : (x,y) or `Vec2d`</span>
<span class="sd">                Define where to check for collision in the space.</span>
<span class="sd">            max_distance : int</span>
<span class="sd">                Maximumm distance of shape from point</span>
<span class="sd">            layers : int</span>
<span class="sd">                Only pick shapes matching the bit mask. i.e. </span>
<span class="sd">                (layers &amp; shape.layers) != 0</span>
<span class="sd">            group : int</span>
<span class="sd">                Only pick shapes not in this group.</span>
<span class="sd">        </span>
<span class="sd">        :Return: </span>
<span class="sd">            [dict(shape=`Shape`, distance = distance, point = Vec2d)]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">def</span> <span class="nf">cf</span><span class="p">(</span><span class="n">_shape</span><span class="p">,</span> <span class="n">distance</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
            <span class="n">shape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">_shape</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span> <span class="n">distance</span><span class="o">=</span><span class="n">distance</span><span class="p">,</span> <span class="n">point</span><span class="o">=</span><span class="n">Vec2d</span><span class="p">(</span><span class="n">point</span><span class="p">)))</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceNearestPointQueryFunc</span><span class="p">(</span><span class="n">cf</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceNearestPointQuery</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">max_distance</span><span class="p">,</span> <span class="n">layers</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span>
    </div>
<div class="viewcode-block" id="Space.nearest_point_query_nearest"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.nearest_point_query_nearest">[docs]</a>    <span class="k">def</span> <span class="nf">nearest_point_query_nearest</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">max_distance</span><span class="p">,</span> <span class="n">layers</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Query space at point filtering out matches with the given layers </span>
<span class="sd">        and group. Return nearest of all shapes within max_distance of the </span>
<span class="sd">        point.</span>
<span class="sd">        </span>
<span class="sd">        If you don&#39;t want to filter out any matches, use -1 for the layers </span>
<span class="sd">        and 0 as the group.</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:    </span>
<span class="sd">            point : (x,y) or `Vec2d`</span>
<span class="sd">                Define where to check for collision in the space.</span>
<span class="sd">            max_distance : int</span>
<span class="sd">                Maximumm distance of shape from point</span>
<span class="sd">            layers : int</span>
<span class="sd">                Only pick shapes matching the bit mask. i.e. </span>
<span class="sd">                (layers &amp; shape.layers) != 0</span>
<span class="sd">            group : int</span>
<span class="sd">                Only pick shapes not in this group.</span>
<span class="sd">        </span>
<span class="sd">        :Return: </span>
<span class="sd">            dict(shape=`Shape`, distance = distance, point = Vec2d)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">info</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpNearestPointQueryInfo</span><span class="p">()</span>
        <span class="n">info_p</span> <span class="o">=</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpNearestPointQueryInfo</span><span class="p">)(</span><span class="n">info</span><span class="p">)</span>
        <span class="n">_shape</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceNearestPointQueryNearest</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">point</span><span class="p">,</span> <span class="n">max_distance</span><span class="p">,</span> <span class="n">layers</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">info_p</span><span class="p">)</span>
        <span class="n">shape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">_shape</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">shape</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">dict</span><span class="p">(</span><span class="n">shape</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span> <span class="n">point</span><span class="o">=</span><span class="n">info</span><span class="o">.</span><span class="n">p</span><span class="p">,</span> <span class="n">distance</span><span class="o">=</span><span class="n">info</span><span class="o">.</span><span class="n">d</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">None</span>        
        

        </div>
<div class="viewcode-block" id="Space.segment_query"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.segment_query">[docs]</a>    <span class="k">def</span> <span class="nf">segment_query</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">layers</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Query space along the line segment from start to end filtering out </span>
<span class="sd">        matches with the given layers and group. </span>
<span class="sd">        </span>
<span class="sd">        Segment queries are like ray casting, but because pymunk uses a </span>
<span class="sd">        spatial hash to process collisions, it cannot process infinitely </span>
<span class="sd">        long queries like a ray. In practice this is still very fast and you </span>
<span class="sd">        don&#39;t need to worry too much about the performance as long as you </span>
<span class="sd">        aren&#39;t using very long segments for your queries. </span>
<span class="sd">        </span>
<span class="sd">        :Return: </span>
<span class="sd">            [`SegmentQueryInfo`] - One SegmentQueryInfo object for each hit.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">def</span> <span class="nf">cf</span><span class="p">(</span><span class="n">_shape</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
            <span class="n">shape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">_shape</span><span class="p">)</span>
            <span class="n">info</span> <span class="o">=</span> <span class="n">SegmentQueryInfo</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">info</span><span class="p">)</span>
        
        <span class="n">f</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceSegmentQueryFunc</span><span class="p">(</span><span class="n">cf</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceSegmentQuery</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">layers</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span>
            </div>
<div class="viewcode-block" id="Space.segment_query_first"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.segment_query_first">[docs]</a>    <span class="k">def</span> <span class="nf">segment_query_first</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">layers</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Query space along the line segment from start to end filtering out </span>
<span class="sd">        matches with the given layers and group. Only the first shape </span>
<span class="sd">        encountered is returned and the search is short circuited. </span>
<span class="sd">        Returns None if no shape was found.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">info</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentQueryInfo</span><span class="p">()</span>
        <span class="n">info_p</span> <span class="o">=</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentQueryInfo</span><span class="p">)(</span><span class="n">info</span><span class="p">)</span>
        <span class="n">_shape</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceSegmentQueryFirst</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">layers</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">info_p</span><span class="p">)</span>
        <span class="n">shape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">_shape</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">shape</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">SegmentQueryInfo</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">t</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">n</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">None</span>
    </div>
<div class="viewcode-block" id="Space.bb_query"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.bb_query">[docs]</a>    <span class="k">def</span> <span class="nf">bb_query</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bb</span><span class="p">,</span> <span class="n">layers</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">group</span> <span class="o">=</span> <span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Perform a fast rectangle query on the space.</span>
<span class="sd">        </span>
<span class="sd">        Only the shape&#39;s bounding boxes are checked for overlap, not their </span>
<span class="sd">        full shape. Returns a list of shapes.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">def</span> <span class="nf">cf</span><span class="p">(</span><span class="n">_shape</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
            
            <span class="n">shape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">_shape</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">shape</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceBBQueryFunc</span><span class="p">(</span><span class="n">cf</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceBBQuery</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">bb</span><span class="o">.</span><span class="n">_bb</span><span class="p">,</span> <span class="n">layers</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span> 
    
    </div>
<div class="viewcode-block" id="Space.shape_query"><a class="viewcode-back" href="../pymunk.html#pymunk.Space.shape_query">[docs]</a>    <span class="k">def</span> <span class="nf">shape_query</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">shape</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Query a space for any shapes overlapping the given shape</span>
<span class="sd">        </span>
<span class="sd">        Returns a list of shapes.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">def</span> <span class="nf">cf</span><span class="p">(</span><span class="n">_shape</span><span class="p">,</span> <span class="n">points</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
            
            <span class="n">shape</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">_shape</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">shape</span><span class="p">)</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceShapeQueryFunc</span><span class="p">(</span><span class="n">cf</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpSpaceShapeQuery</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">,</span> <span class="n">shape</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__query_hits</span>
        </div></div>
<div class="viewcode-block" id="Body"><a class="viewcode-back" href="../pymunk.html#pymunk.Body">[docs]</a><span class="k">class</span> <span class="nc">Body</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;A rigid body</span>
<span class="sd">    </span>
<span class="sd">    * Use forces to modify the rigid bodies if possible. This is likely to be </span>
<span class="sd">      the most stable.</span>
<span class="sd">    * Modifying a body&#39;s velocity shouldn&#39;t necessarily be avoided, but </span>
<span class="sd">      applying large changes can cause strange results in the simulation. </span>
<span class="sd">      Experiment freely, but be warned.</span>
<span class="sd">    * Don&#39;t modify a body&#39;s position every step unless you really know what </span>
<span class="sd">      you are doing. Otherwise you&#39;re likely to get the position/velocity badly </span>
<span class="sd">      out of sync. </span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Body.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mass</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">moment</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Create a new Body</span>
<span class="sd">        </span>
<span class="sd">        To create a static body, pass in None for mass and moment.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">mass</span> <span class="o">==</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">moment</span> <span class="o">==</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_body</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyNewStatic</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_body</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyNew</span><span class="p">(</span><span class="n">mass</span><span class="p">,</span> <span class="n">moment</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="o">.</span><span class="n">contents</span> 
        <span class="bp">self</span><span class="o">.</span><span class="n">_position_callback</span> <span class="o">=</span> <span class="bp">None</span> <span class="c"># To prevent the gc to collect the callbacks.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_velocity_callback</span> <span class="o">=</span> <span class="bp">None</span> <span class="c"># To prevent the gc to collect the callbacks.</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span> <span class="o">=</span> <span class="bp">None</span> <span class="c"># Weak ref to the space holding this body (if any)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span> <span class="o">=</span> <span class="n">WeakSet</span><span class="p">()</span> <span class="c"># weak refs to any constraints attached</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapes</span> <span class="o">=</span> <span class="n">WeakSet</span><span class="p">()</span> <span class="c"># weak refs to any shapes attached</span>
        </div>
    <span class="k">def</span> <span class="nf">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyFree</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>
        <span class="k">except</span><span class="p">:</span> 
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_mass</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mass</span><span class="p">):</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodySetMass</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">mass</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">_get_mass</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">m</span>
    <span class="n">mass</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_mass</span><span class="p">,</span> <span class="n">_set_mass</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_moment</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">moment</span><span class="p">):</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodySetMoment</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">moment</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">_get_moment</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">i</span>
    <span class="n">moment</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_moment</span><span class="p">,</span> <span class="n">_set_moment</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_angle</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">angle</span><span class="p">):</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodySetAngle</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">angle</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">_get_angle</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">a</span>
    <span class="n">angle</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_angle</span><span class="p">,</span> <span class="n">_set_angle</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The rotation of the body. </span>
<span class="s">        </span>
<span class="s">        .. Note:: </span>
<span class="s">            If you get small/no changes to the angle when for example a </span>
<span class="s">            ball is &quot;rolling&quot; down a slope it might be because the Circle shape </span>
<span class="s">            attached to the body or the slope shape does not have any friction </span>
<span class="s">            set.&quot;&quot;&quot;</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_get_rotation_vector</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">rot</span>
    <span class="n">rotation_vector</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_rotation_vector</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_torque</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">t</span> <span class="o">=</span> <span class="n">t</span>
    <span class="k">def</span> <span class="nf">_get_torque</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">t</span>
    <span class="n">torque</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_torque</span><span class="p">,</span> <span class="n">_set_torque</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_position</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pos</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">p</span> <span class="o">=</span> <span class="n">pos</span>
    <span class="k">def</span> <span class="nf">_get_position</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">p</span>
    <span class="n">position</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_position</span><span class="p">,</span> <span class="n">_set_position</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_velocity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vel</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">v</span> <span class="o">=</span> <span class="n">vel</span>
    <span class="k">def</span> <span class="nf">_get_velocity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">v</span>
    <span class="n">velocity</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_velocity</span><span class="p">,</span> <span class="n">_set_velocity</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_velocity_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vel</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">v_limit</span> <span class="o">=</span> <span class="n">vel</span>
    <span class="k">def</span> <span class="nf">_get_velocity_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">v_limit</span>
    <span class="n">velocity_limit</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_velocity_limit</span><span class="p">,</span> <span class="n">_set_velocity_limit</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_set_angular_velocity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">w</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">w</span> <span class="o">=</span> <span class="n">w</span>
    <span class="k">def</span> <span class="nf">_get_angular_velocity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">w</span>
    <span class="n">angular_velocity</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_angular_velocity</span><span class="p">,</span> <span class="n">_set_angular_velocity</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_angular_velocity_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">w</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">w_limit</span> <span class="o">=</span> <span class="n">w</span>
    <span class="k">def</span> <span class="nf">_get_angular_velocity_limit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">w_limit</span>
    <span class="n">angular_velocity_limit</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_angular_velocity_limit</span><span class="p">,</span> <span class="n">_set_angular_velocity_limit</span><span class="p">)</span>
    
    
    <span class="k">def</span> <span class="nf">_set_force</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">f</span>
    <span class="k">def</span> <span class="nf">_get_force</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">f</span>
    <span class="n">force</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_force</span><span class="p">,</span> <span class="n">_set_force</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_velocity_func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;The velocity callback function. The velocity callback function </span>
<span class="sd">        is called each time step, and can be used to set a body&#39;s velocity.</span>
<span class="sd">        </span>
<span class="sd">            ``func(body, gravity, damping, dt) -&gt; None``</span>
<span class="sd">            </span>
<span class="sd">            Callback Parameters</span>
<span class="sd">                body : `Body`</span>
<span class="sd">                    Body that should have its velocity calculated</span>
<span class="sd">                gravity : `Vec2d`</span>
<span class="sd">                    The gravity vector</span>
<span class="sd">                damping : float</span>
<span class="sd">                    The damping</span>
<span class="sd">                dt : float</span>
<span class="sd">                    Delta time since last step.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="k">def</span> <span class="nf">_impl</span><span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">gravity</span><span class="p">,</span> <span class="n">damping</span><span class="p">,</span> <span class="n">dt</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">gravity</span><span class="p">,</span> <span class="n">damping</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_velocity_callback</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyVelocityFunc</span><span class="p">(</span><span class="n">_impl</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">velocity_func</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_velocity_callback</span>
    <span class="n">velocity_func</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">fset</span><span class="o">=</span><span class="n">_set_velocity_func</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="n">_set_velocity_func</span><span class="o">.</span><span class="n">__doc__</span><span class="p">)</span>    

    <span class="k">def</span> <span class="nf">_set_position_func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;The position callback function. The position callback function </span>
<span class="sd">        is called each time step and can be used to update the body&#39;s position.</span>
<span class="sd">        </span>
<span class="sd">            ``func(body, dt) -&gt; None``</span>
<span class="sd">            </span>
<span class="sd">            Callback Parameters</span>
<span class="sd">                body : `Body`</span>
<span class="sd">                    Body that should have its velocity calculated</span>
<span class="sd">                dt : float</span>
<span class="sd">                    Delta time since last step.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="k">def</span> <span class="nf">_impl</span><span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">dt</span><span class="p">):</span>
            <span class="n">func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_position_callback</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyPositionFunc</span><span class="p">(</span><span class="n">_impl</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">position_func</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_position_callback</span>
    <span class="n">position_func</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">fset</span><span class="o">=</span><span class="n">_set_position_func</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="n">_set_position_func</span><span class="o">.</span><span class="n">__doc__</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_get_kinetic_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c">#todo: use ffi method</span>
        <span class="c">#return cp._cpBodyKineticEnergy(self._body)</span>
        
        <span class="n">vsq</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocity</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">velocity</span><span class="p">)</span>
        <span class="n">wsq</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">angular_velocity</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">angular_velocity</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">vsq</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">mass</span> <span class="k">if</span> <span class="n">vsq</span> <span class="k">else</span> <span class="mf">0.</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="n">wsq</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">moment</span> <span class="k">if</span> <span class="n">wsq</span> <span class="k">else</span> <span class="mf">0.</span><span class="p">)</span>
    
    <span class="n">kinetic_energy</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_kinetic_energy</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Get the kinetic energy of a body.&quot;&quot;&quot;</span><span class="p">)</span>
    
    
    <span class="nd">@staticmethod</span>
<div class="viewcode-block" id="Body.update_velocity"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.update_velocity">[docs]</a>    <span class="k">def</span> <span class="nf">update_velocity</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="n">gravity</span><span class="p">,</span> <span class="n">damping</span><span class="p">,</span> <span class="n">dt</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Default rigid body velocity integration function. </span>
<span class="sd">        </span>
<span class="sd">        Updates the velocity of the body using Euler integration.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyUpdateVelocity</span><span class="p">(</span><span class="n">body</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">gravity</span><span class="p">,</span> <span class="n">damping</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span>
</div>
    <span class="nd">@staticmethod</span>
<div class="viewcode-block" id="Body.update_position"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.update_position">[docs]</a>    <span class="k">def</span> <span class="nf">update_position</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="n">dt</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Default rigid body position integration function. </span>
<span class="sd">        </span>
<span class="sd">        Updates the position of the body using Euler integration. Unlike the </span>
<span class="sd">        velocity function, it&#39;s unlikely you&#39;ll want to override this </span>
<span class="sd">        function. If you do, make sure you understand it&#39;s source code </span>
<span class="sd">        (in Chipmunk) as it&#39;s an important part of the collision/joint </span>
<span class="sd">        correction process. </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyUpdatePosition</span><span class="p">(</span><span class="n">body</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="Body.apply_impulse"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.apply_impulse">[docs]</a>    <span class="k">def</span> <span class="nf">apply_impulse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">r</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;Apply the impulse j to body at a relative offset (important!) r </span>
<span class="sd">        from the center of gravity. Both r and j are in world coordinates. </span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            j : (x,y) or `Vec2d`</span>
<span class="sd">                Impulse to be applied</span>
<span class="sd">            r : (x,y) or `Vec2d`</span>
<span class="sd">                Offset the impulse with this vector</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyApplyImpulse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="Body.reset_forces"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.reset_forces">[docs]</a>    <span class="k">def</span> <span class="nf">reset_forces</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Zero both the forces and torques accumulated on body&quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyResetForces</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Body.apply_force"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.apply_force">[docs]</a>    <span class="k">def</span> <span class="nf">apply_force</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">r</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;Apply (accumulate) the force f on body at a relative offset </span>
<span class="sd">        (important!) r from the center of gravity. </span>
<span class="sd">        </span>
<span class="sd">        Both r and f are in world coordinates. </span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            f : (x,y) or `Vec2d`</span>
<span class="sd">                Force in world coordinates</span>
<span class="sd">            r : (x,y) or `Vec2d`</span>
<span class="sd">                Offset in world coordinates</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyApplyForce</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
                </div>
<div class="viewcode-block" id="Body.activate"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.activate">[docs]</a>    <span class="k">def</span> <span class="nf">activate</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Wake up a sleeping or idle body.&quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyActivate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="Body.sleep"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.sleep">[docs]</a>    <span class="k">def</span> <span class="nf">sleep</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Force a body to fall asleep immediately.&quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodySleep</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>    
        </div>
<div class="viewcode-block" id="Body.sleep_with_group"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.sleep_with_group">[docs]</a>    <span class="k">def</span> <span class="nf">sleep_with_group</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">body</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Force a body to fall asleep immediately along with other bodies in a group.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodySleepWithGroup</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">body</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>
        </div>
    <span class="k">def</span> <span class="nf">_is_sleeping</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cpffi</span><span class="o">.</span><span class="n">cpBodyIsSleeping</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>
        <span class="c">#todo: use ffi function</span>
        <span class="c">#return bool(self._bodycontents.node_private.root)</span>
    <span class="n">is_sleeping</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_is_sleeping</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Returns true if the body is sleeping.&quot;&quot;&quot;</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_is_rogue</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cpffi</span><span class="o">.</span><span class="n">cpBodyIsRogue</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>
        <span class="c">#todo: use ffi function</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bodycontents</span><span class="o">.</span><span class="n">space_private</span><span class="p">)</span>
    <span class="n">is_rogue</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_is_rogue</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Returns true if the body has not been added to a space.&quot;&quot;&quot;</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_is_static</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cpffi</span><span class="o">.</span><span class="n">cpBodyIsStatic</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">)</span>
    <span class="n">is_static</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_is_static</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Returns true if the body is a static body&quot;&quot;&quot;</span><span class="p">)</span>
    
<div class="viewcode-block" id="Body.each_arbiter"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.each_arbiter">[docs]</a>    <span class="k">def</span> <span class="nf">each_arbiter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Run func on each of the arbiters on this body.</span>
<span class="sd">        </span>
<span class="sd">            ``func(arbiter, *args, **kwargs) -&gt; None``</span>
<span class="sd">            </span>
<span class="sd">            Callback Parameters</span>
<span class="sd">                arbiter : `Arbiter`</span>
<span class="sd">                    The Arbiter</span>
<span class="sd">                args</span>
<span class="sd">                    Optional parameters passed to the callback function.</span>
<span class="sd">                kwargs</span>
<span class="sd">                    Optional keyword parameters passed on to the callback function.</span>
<span class="sd">                    </span>
<span class="sd">        .. warning::</span>
<span class="sd">            </span>
<span class="sd">            Do not hold on to the Arbiter after the callback!                </span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="k">def</span> <span class="nf">impl</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="n">_arbiter</span><span class="p">,</span> <span class="n">_</span><span class="p">):</span>
            <span class="n">arbiter</span> <span class="o">=</span> <span class="n">Arbiter</span><span class="p">(</span><span class="n">_arbiter</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="p">)</span>
            <span class="n">func</span><span class="p">(</span><span class="n">arbiter</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyArbiterIteratorFunc</span><span class="p">(</span><span class="n">impl</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpBodyEachArbiter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        </div>
    <span class="k">def</span> <span class="nf">_get_constraints</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_constraints</span><span class="p">)</span>
    
    <span class="n">constraints</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_constraints</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Get the constraints this body is attached to.&quot;&quot;&quot;</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_get_shapes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shapes</span><span class="p">)</span>
    
    <span class="n">shapes</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_shapes</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Get the shapes attached to this body.&quot;&quot;&quot;</span><span class="p">)</span>
    
<div class="viewcode-block" id="Body.local_to_world"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.local_to_world">[docs]</a>    <span class="k">def</span> <span class="nf">local_to_world</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Convert body local coordinates to world space coordinates</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            v : (x,y) or `Vec2d`</span>
<span class="sd">                Vector in body local coordinates</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">cpffi</span><span class="o">.</span><span class="n">cpBodyLocal2World</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="Body.world_to_local"><a class="viewcode-back" href="../pymunk.html#pymunk.Body.world_to_local">[docs]</a>    <span class="k">def</span> <span class="nf">world_to_local</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Convert world space coordinates to body local coordinates</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            v : (x,y) or `Vec2d`</span>
<span class="sd">                Vector in world space coordinates</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">cpffi</span><span class="o">.</span><span class="n">cpBodyWorld2Local</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
        

</div></div>
<div class="viewcode-block" id="Shape"><a class="viewcode-back" href="../pymunk.html#pymunk.Shape">[docs]</a><span class="k">class</span> <span class="nc">Shape</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Base class for all the shapes. </span>
<span class="sd">    </span>
<span class="sd">    You usually dont want to create instances of this class directly but use </span>
<span class="sd">    one of the specialized shapes instead.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Shape.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.Shape.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span> <span class="o">=</span> <span class="n">shape</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="o">.</span><span class="n">contents</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_body</span> <span class="o">=</span> <span class="n">shape</span><span class="o">.</span><span class="n">body</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="bp">None</span>
</div>
    <span class="k">def</span> <span class="nf">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">cp</span><span class="o">.</span><span class="n">cpShapeFree</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">)</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="k">pass</span>
            
    <span class="k">def</span> <span class="nf">_get_hashid_private</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">hashid_private</span>
    <span class="n">_hashid_private</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_hashid_private</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_get_sensor</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">sensor</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">_set_sensor</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">is_sensor</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">sensor</span> <span class="o">=</span> <span class="n">is_sensor</span>
    <span class="n">sensor</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_sensor</span><span class="p">,</span> <span class="n">_set_sensor</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;A boolean value if this shape is a sensor or not. Sensors only</span>
<span class="s">        call collision callbacks, and never generate real collisions.&quot;&quot;&quot;</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_get_collision_type</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">collision_type</span>
    <span class="k">def</span> <span class="nf">_set_collision_type</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">collision_type</span> <span class="o">=</span> <span class="n">t</span>
    <span class="n">collision_type</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_collision_type</span><span class="p">,</span> <span class="n">_set_collision_type</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;User defined collision type for the shape. See </span>
<span class="s">        add_collisionpair_func function for more information on when to use </span>
<span class="s">        this property&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_group</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">group</span>
    <span class="k">def</span> <span class="nf">_set_group</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">group</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">group</span> <span class="o">=</span> <span class="n">group</span>
    <span class="n">group</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_group</span><span class="p">,</span> <span class="n">_set_group</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Shapes in the same non-zero group do not generate collisions. </span>
<span class="s">        Useful when creating an object out of many shapes that you don&#39;t want </span>
<span class="s">        to self collide. Defaults to 0&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_layers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">layers</span>
    <span class="k">def</span> <span class="nf">_set_layers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">layers</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">layers</span> <span class="o">=</span> <span class="n">layers</span>
    <span class="n">layers</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_layers</span><span class="p">,</span> <span class="n">_set_layers</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Shapes only collide if they are in the same bit-planes. </span>
<span class="s">        i.e. (a.layers &amp; b.layers) != 0. By default, a shape occupies all </span>
<span class="s">        32 bit-planes, i.e. layers == -1&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_elasticity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">e</span>
    <span class="k">def</span> <span class="nf">_set_elasticity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">e</span> <span class="o">=</span> <span class="n">e</span>
    <span class="n">elasticity</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_elasticity</span><span class="p">,</span> <span class="n">_set_elasticity</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Elasticity of the shape. A value of 0.0 gives no bounce, </span>
<span class="s">        while a value of 1.0 will give a &#39;perfect&#39; bounce. However due to </span>
<span class="s">        inaccuracies in the simulation using 1.0 or greater is not </span>
<span class="s">        recommended.&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_friction</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">u</span>
    <span class="k">def</span> <span class="nf">_set_friction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">u</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">u</span> <span class="o">=</span> <span class="n">u</span>
    <span class="n">friction</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_friction</span><span class="p">,</span> <span class="n">_set_friction</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Friction coefficient. pymunk uses the Coulomb friction model, a </span>
<span class="s">        value of 0.0 is frictionless.</span>
<span class="s">        </span>
<span class="s">        A value over 1.0 is perfectly fine.</span>
<span class="s">        </span>
<span class="s">        Some real world example values from wikipedia (Remember that </span>
<span class="s">        it is what looks good that is important, not the exact value).</span>
<span class="s">        </span>
<span class="s">        ==============  ======  ========</span>
<span class="s">        Material        Other   Friction</span>
<span class="s">        ==============  ======  ========</span>
<span class="s">        Aluminium       Steel   0.61</span>
<span class="s">        Copper          Steel   0.53</span>
<span class="s">        Brass           Steel   0.51</span>
<span class="s">        Cast iron       Copper  1.05</span>
<span class="s">        Cast iron       Zinc    0.85</span>
<span class="s">        Concrete (wet)  Rubber  0.30</span>
<span class="s">        Concrete (dry)  Rubber  1.0 </span>
<span class="s">        Concrete        Wood    0.62</span>
<span class="s">        Copper          Glass   0.68</span>
<span class="s">        Glass           Glass   0.94</span>
<span class="s">        Metal           Wood    0.5</span>
<span class="s">        Polyethene      Steel   0.2</span>
<span class="s">        Steel           Steel   0.80</span>
<span class="s">        Steel           Teflon  0.04</span>
<span class="s">        Teflon (PTFE)   Teflon  0.04</span>
<span class="s">        Wood            Wood    0.4</span>
<span class="s">        ==============  ======  ========</span>
<span class="s">        &quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_surface_velocity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">surface_v</span>
    <span class="k">def</span> <span class="nf">_set_surface_velocity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">surface_v</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">surface_v</span> <span class="o">=</span> <span class="n">surface_v</span>
    <span class="n">surface_velocity</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_surface_velocity</span><span class="p">,</span> <span class="n">_set_surface_velocity</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The surface velocity of the object. Useful for creating </span>
<span class="s">        conveyor belts or players that move around. This value is only used </span>
<span class="s">        when calculating friction, not resolving the collision.&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_body</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_body</span>
    <span class="k">def</span> <span class="nf">_set_body</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">body</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_body</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="o">.</span><span class="n">_shapes</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">body</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">body</span><span class="o">.</span><span class="n">_shapes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">body</span> <span class="o">=</span> <span class="n">body</span><span class="o">.</span><span class="n">_body</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span><span class="o">.</span><span class="n">body</span> <span class="o">=</span> <span class="bp">None</span>
            
        <span class="bp">self</span><span class="o">.</span><span class="n">_body</span> <span class="o">=</span> <span class="n">body</span>
        
    <span class="n">body</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_body</span><span class="p">,</span> <span class="n">_set_body</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The body this shape is attached to. Can be set to None to </span>
<span class="s">        indicate that this shape doesnt belong to a body.&quot;&quot;&quot;</span><span class="p">)</span>

<div class="viewcode-block" id="Shape.update"><a class="viewcode-back" href="../pymunk.html#pymunk.Shape.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">position</span><span class="p">,</span> <span class="n">rotation_vector</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Update, cache and return the bounding box of a shape with an </span>
<span class="sd">        explicit transformation.</span>
<span class="sd">        </span>
<span class="sd">        Useful if you have a shape without a body and want to use it for </span>
<span class="sd">        querying.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">BB</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpShapeUpdate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">position</span><span class="p">,</span> <span class="n">rotation_vector</span><span class="p">))</span>
        </div>
<div class="viewcode-block" id="Shape.cache_bb"><a class="viewcode-back" href="../pymunk.html#pymunk.Shape.cache_bb">[docs]</a>    <span class="k">def</span> <span class="nf">cache_bb</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Update and returns the bouding box of this shape&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">BB</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpShapeCacheBB</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">))</span>
</div>
    <span class="k">def</span> <span class="nf">_get_bb</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">BB</span><span class="p">(</span><span class="n">cpffi</span><span class="o">.</span><span class="n">cpShapeGetBB</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">))</span>
        
    <span class="n">bb</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_bb</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The bounding box of the shape.</span>
<span class="s">    Only guaranteed to be valid after Shape.cache_bb() or Space.step() is </span>
<span class="s">    called. Moving a body that a shape is connected to does not update it&#39;s </span>
<span class="s">    bounding box. For shapes used for queries that aren&#39;t attached to bodies, </span>
<span class="s">    you can also use Shape.update().</span>
<span class="s">    &quot;&quot;&quot;</span><span class="p">)</span>
        
<div class="viewcode-block" id="Shape.point_query"><a class="viewcode-back" href="../pymunk.html#pymunk.Shape.point_query">[docs]</a>    <span class="k">def</span> <span class="nf">point_query</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Check if the given point lies within the shape.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpShapePointQuery</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">p</span><span class="p">))</span>
        </div>
<div class="viewcode-block" id="Shape.segment_query"><a class="viewcode-back" href="../pymunk.html#pymunk.Shape.segment_query">[docs]</a>    <span class="k">def</span> <span class="nf">segment_query</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Check if the line segment from start to end intersects the shape. </span>
<span class="sd">        </span>
<span class="sd">        Return either SegmentQueryInfo object or None</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">info</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentQueryInfo</span><span class="p">()</span>
        <span class="n">info_p</span> <span class="o">=</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentQueryInfo</span><span class="p">)(</span><span class="n">info</span><span class="p">)</span>
        <span class="n">r</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpShapeSegmentQuery</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">info_p</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">bool</span><span class="p">(</span><span class="n">r</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">SegmentQueryInfo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">t</span><span class="p">,</span> <span class="n">info</span><span class="o">.</span><span class="n">n</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>
    

    </div></div>
<div class="viewcode-block" id="Circle"><a class="viewcode-back" href="../pymunk.html#pymunk.Circle">[docs]</a><span class="k">class</span> <span class="nc">Circle</span><span class="p">(</span><span class="n">Shape</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;A circle shape defined by a radius</span>
<span class="sd">    </span>
<span class="sd">    This is the fastest and simplest collision shape</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Circle.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.Circle.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span> <span class="n">radius</span><span class="p">,</span> <span class="n">offset</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;body is the body attach the circle to, offset is the offset from the</span>
<span class="sd">        body&#39;s center of gravity in body local coordinates.</span>
<span class="sd">        </span>
<span class="sd">        It is legal to send in None as body argument to indicate that this </span>
<span class="sd">        shape is not attached to a body.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_body</span> <span class="o">=</span> <span class="n">body</span>
        <span class="n">body_body</span> <span class="o">=</span> <span class="bp">None</span> <span class="k">if</span> <span class="n">body</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">body</span><span class="o">.</span><span class="n">_body</span>
        <span class="k">if</span> <span class="n">body</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> 
            <span class="n">body</span><span class="o">.</span><span class="n">_shapes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpCircleShapeNew</span><span class="p">(</span><span class="n">body_body</span><span class="p">,</span> <span class="n">radius</span><span class="p">,</span> <span class="n">offset</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="o">.</span><span class="n">contents</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cs</span> <span class="o">=</span> <span class="n">ct</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpCircleShape</span><span class="p">))</span>
        
        </div>
<div class="viewcode-block" id="Circle.unsafe_set_radius"><a class="viewcode-back" href="../pymunk.html#pymunk.Circle.unsafe_set_radius">[docs]</a>    <span class="k">def</span> <span class="nf">unsafe_set_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">r</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Unsafe set the radius of the circle. </span>
<span class="sd">    </span>
<span class="sd">        .. note:: </span>
<span class="sd">            This change is only picked up as a change to the position </span>
<span class="sd">            of the shape&#39;s surface, but not it&#39;s velocity. Changing it will </span>
<span class="sd">            not result in realistic physical behavior. Only use if you know </span>
<span class="sd">            what you are doing!</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpCircleShapeSetRadius</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
        </div>
    <span class="k">def</span> <span class="nf">_get_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpCircleShapeGetRadius</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">)</span>
    <span class="n">radius</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_radius</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The Radius of the circle&quot;&quot;&quot;</span><span class="p">)</span>

<div class="viewcode-block" id="Circle.unsafe_set_offset"><a class="viewcode-back" href="../pymunk.html#pymunk.Circle.unsafe_set_offset">[docs]</a>    <span class="k">def</span> <span class="nf">unsafe_set_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">o</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Unsafe set the offset of the circle. </span>
<span class="sd">    </span>
<span class="sd">        .. note:: </span>
<span class="sd">            This change is only picked up as a change to the position </span>
<span class="sd">            of the shape&#39;s surface, but not it&#39;s velocity. Changing it will </span>
<span class="sd">            not result in realistic physical behavior. Only use if you know </span>
<span class="sd">            what you are doing!</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpCircleShapeSetOffset</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">o</span><span class="p">)</span>
    </div>
    <span class="k">def</span> <span class="nf">_get_offset</span> <span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpCircleShapeGetOffset</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">)</span>
    <span class="n">offset</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_offset</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Offset. (body space coordinates)&quot;&quot;&quot;</span><span class="p">)</span>

    </div>
<div class="viewcode-block" id="Segment"><a class="viewcode-back" href="../pymunk.html#pymunk.Segment">[docs]</a><span class="k">class</span> <span class="nc">Segment</span><span class="p">(</span><span class="n">Shape</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;A line segment shape between two points</span>
<span class="sd">    </span>
<span class="sd">    This shape can be attached to moving bodies, but don&#39;t currently generate </span>
<span class="sd">    collisions with other line segments. Can be beveled in order to give it a </span>
<span class="sd">    thickness. </span>
<span class="sd">    </span>
<span class="sd">    It is legal to send in None as body argument to indicate that this </span>
<span class="sd">    shape is not attached to a body.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Segment.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.Segment.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">radius</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Create a Segment</span>
<span class="sd">        </span>
<span class="sd">        :Parameters:</span>
<span class="sd">            body : `Body`</span>
<span class="sd">                The body to attach the segment to</span>
<span class="sd">            a : (x,y) or `Vec2d`</span>
<span class="sd">                The first endpoint of the segment</span>
<span class="sd">            b : (x,y) or `Vec2d`</span>
<span class="sd">                The second endpoint of the segment</span>
<span class="sd">            radius : float</span>
<span class="sd">                The thickness of the segment</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_body</span> <span class="o">=</span> <span class="n">body</span>
        <span class="n">body_body</span> <span class="o">=</span> <span class="bp">None</span> <span class="k">if</span> <span class="n">body</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">body</span><span class="o">.</span><span class="n">_body</span>
        <span class="k">if</span> <span class="n">body</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> 
            <span class="n">body</span><span class="o">.</span><span class="n">_shapes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentShapeNew</span><span class="p">(</span><span class="n">body_body</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">radius</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="o">.</span><span class="n">contents</span>
    
    <span class="c">#TODO: Add/rename set methods to unsafe in next major release?</span>
    </div>
    <span class="k">def</span> <span class="nf">_set_a</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a</span><span class="p">):</span>
        <span class="n">ct</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentShape</span><span class="p">))</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="n">a</span>
    <span class="k">def</span> <span class="nf">_get_a</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">ct</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentShape</span><span class="p">))</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">a</span>
    <span class="n">a</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_a</span><span class="p">,</span> <span class="n">_set_a</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The first of the two endpoints for this segment&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_b</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
        <span class="n">ct</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentShape</span><span class="p">))</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="n">b</span>
    <span class="k">def</span> <span class="nf">_get_b</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">ct</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentShape</span><span class="p">))</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">b</span>
    <span class="n">b</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_b</span><span class="p">,</span> <span class="n">_set_b</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The second of the two endpoints for this segment&quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_set_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">r</span><span class="p">):</span>
        <span class="n">ct</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentShape</span><span class="p">))</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">r</span> <span class="o">=</span> <span class="n">r</span>
    <span class="k">def</span> <span class="nf">_get_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">ct</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpSegmentShape</span><span class="p">))</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">r</span>
    <span class="n">radius</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_radius</span><span class="p">,</span> <span class="n">_set_radius</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The thickness of the segment&quot;&quot;&quot;</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="Poly"><a class="viewcode-back" href="../pymunk.html#pymunk.Poly">[docs]</a><span class="k">class</span> <span class="nc">Poly</span><span class="p">(</span><span class="n">Shape</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;A convex polygon shape</span>
<span class="sd">    </span>
<span class="sd">    Slowest, but most flexible collision shape.</span>

<span class="sd">    It is legal to send in None as body argument to indicate that this </span>
<span class="sd">    shape is not attached to a body.    </span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Poly.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.Poly.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span> <span class="n">vertices</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">auto_order_vertices</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">radius</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Create a polygon</span>
<span class="sd">        </span>
<span class="sd">            body : `Body`</span>
<span class="sd">                The body to attach the poly to</span>
<span class="sd">            vertices : [(x,y)] or [`Vec2d`]</span>
<span class="sd">                Define a convex hull of the polygon with a counterclockwise</span>
<span class="sd">                winding.</span>
<span class="sd">            offset : (x,y) or `Vec2d`</span>
<span class="sd">                The offset from the body&#39;s center of gravity in body local </span>
<span class="sd">                coordinates. </span>
<span class="sd">            auto_order_vertices : bool </span>
<span class="sd">                Set to True to automatically order the vertices. If you know </span>
<span class="sd">                the vertices are in the correct (clockwise) orded you can gain </span>
<span class="sd">                a little performance by setting this to False.</span>
<span class="sd">            radius : int</span>
<span class="sd">                Set the radius of the poly shape.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_body</span> <span class="o">=</span> <span class="n">body</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">offset</span> <span class="o">=</span> <span class="n">offset</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_verts</span><span class="p">(</span><span class="n">vertices</span><span class="p">,</span> <span class="n">auto_order_vertices</span><span class="p">)</span>
                
        <span class="n">body_body</span> <span class="o">=</span> <span class="bp">None</span> <span class="k">if</span> <span class="n">body</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">body</span><span class="o">.</span><span class="n">_body</span>
        <span class="k">if</span> <span class="n">body</span> <span class="o">!=</span> <span class="bp">None</span><span class="p">:</span> 
            <span class="n">body</span><span class="o">.</span><span class="n">_shapes</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpPolyShapeNew2</span><span class="p">(</span><span class="n">body_body</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">vertices</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">verts</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">radius</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shapecontents</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="o">.</span><span class="n">contents</span>
</div>
<div class="viewcode-block" id="Poly.unsafe_set_radius"><a class="viewcode-back" href="../pymunk.html#pymunk.Poly.unsafe_set_radius">[docs]</a>    <span class="k">def</span> <span class="nf">unsafe_set_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">radius</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Unsafe set the radius of the poly.</span>

<span class="sd">        .. note:: </span>
<span class="sd">            This change is only picked up as a change to the position </span>
<span class="sd">            of the shape&#39;s surface, but not it&#39;s velocity. Changing it will </span>
<span class="sd">            not result in realistic physical behavior. Only use if you know </span>
<span class="sd">            what you are doing!</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpPolyShapeSetRadius</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="n">radius</span><span class="p">)</span>    
    </div>
    <span class="k">def</span> <span class="nf">_get_radius</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpPolyShapeGetRadius</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">)</span>
    <span class="n">radius</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_radius</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The radius of the poly shape. Extends the poly in all </span>
<span class="s">        directions with the given radius&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_verts</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vertices</span><span class="p">,</span> <span class="n">auto_order_vertices</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">verts</span> <span class="o">=</span> <span class="p">(</span><span class="n">Vec2d</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">vertices</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">verts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">verts</span><span class="p">(</span><span class="n">Vec2d</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
        
        <span class="n">i_vs</span> <span class="o">=</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">vertices</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">auto_order_vertices</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">u</span><span class="o">.</span><span class="n">is_clockwise</span><span class="p">(</span><span class="n">vertices</span><span class="p">):</span>
            <span class="n">i_vs</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">vertices</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">),</span> <span class="n">vertices</span><span class="p">)</span>
        
        <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">vertex</span><span class="p">)</span> <span class="ow">in</span> <span class="n">i_vs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">verts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">vertex</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">verts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">vertex</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        
    <span class="nd">@staticmethod</span>
<div class="viewcode-block" id="Poly.create_box"><a class="viewcode-back" href="../pymunk.html#pymunk.Poly.create_box">[docs]</a>    <span class="k">def</span> <span class="nf">create_box</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">10</span><span class="p">),</span> <span class="n">offset</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="n">radius</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span> 
        <span class="sd">&quot;&quot;&quot;Convenience function to create a box centered around the body position.</span>

<span class="sd">        The size is given as as (w,h) tuple.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="o">=</span> <span class="n">size</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">*.</span><span class="mi">5</span><span class="p">,</span><span class="n">size</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">*.</span><span class="mi">5</span>
        <span class="n">vs</span> <span class="o">=</span> <span class="p">[(</span><span class="o">-</span><span class="n">x</span><span class="p">,</span><span class="o">-</span><span class="n">y</span><span class="p">),(</span><span class="o">-</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">),(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">),(</span><span class="n">x</span><span class="p">,</span><span class="o">-</span><span class="n">y</span><span class="p">)]</span>
    
        <span class="k">return</span> <span class="n">Poly</span><span class="p">(</span><span class="n">body</span><span class="p">,</span> <span class="n">vs</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">radius</span><span class="p">)</span>
        
        </div>
<div class="viewcode-block" id="Poly.get_vertices"><a class="viewcode-back" href="../pymunk.html#pymunk.Poly.get_vertices">[docs]</a>    <span class="k">def</span> <span class="nf">get_vertices</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> 
        <span class="sd">&quot;&quot;&quot;Get the vertices in world coordinates for the polygon</span>
<span class="sd">        </span>
<span class="sd">        :return: [`Vec2d`] in world coords</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c">#shape = ct.cast(self._shape, ct.POINTER(cp.cpPolyShape))</span>
        <span class="c">#num = shape.contents.numVerts</span>
        <span class="c">#verts = shape.contents.verts</span>
        <span class="n">points</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">rv</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="o">.</span><span class="n">rotation_vector</span>
        <span class="n">bp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_body</span><span class="o">.</span><span class="n">position</span>
        <span class="n">vs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">verts</span>
        <span class="n">o</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">offset</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">vs</span><span class="p">)):</span>
            <span class="n">p</span> <span class="o">=</span> <span class="p">(</span><span class="n">vs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="n">o</span><span class="p">)</span><span class="o">.</span><span class="n">cpvrotate</span><span class="p">(</span><span class="n">rv</span><span class="p">)</span><span class="o">+</span><span class="n">bp</span>
            <span class="n">points</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Vec2d</span><span class="p">(</span><span class="n">p</span><span class="p">))</span>
            
        <span class="k">return</span> <span class="n">points</span>
</div>
<div class="viewcode-block" id="Poly.unsafe_set_vertices"><a class="viewcode-back" href="../pymunk.html#pymunk.Poly.unsafe_set_vertices">[docs]</a>    <span class="k">def</span> <span class="nf">unsafe_set_vertices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vertices</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">auto_order_vertices</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Unsafe set the vertices of the poly. </span>
<span class="sd">    </span>
<span class="sd">        .. note:: </span>
<span class="sd">            This change is only picked up as a change to the position </span>
<span class="sd">            of the shape&#39;s surface, but not it&#39;s velocity. Changing it will </span>
<span class="sd">            not result in realistic physical behavior. Only use if you know </span>
<span class="sd">            what you are doing!</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_verts</span><span class="p">(</span><span class="n">vertices</span><span class="p">,</span> <span class="n">auto_order_vertices</span><span class="p">)</span>
        <span class="n">cp</span><span class="o">.</span><span class="n">cpPolyShapeSetVerts</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_shape</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">vertices</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">verts</span><span class="p">,</span> <span class="n">offset</span><span class="p">)</span>
        
        </div></div>
<div class="viewcode-block" id="SegmentQueryInfo"><a class="viewcode-back" href="../pymunk.html#pymunk.SegmentQueryInfo">[docs]</a><span class="k">class</span> <span class="nc">SegmentQueryInfo</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Segment queries return more information than just a simple yes or no, </span>
<span class="sd">    they also return where a shape was hit and it&#39;s surface normal at the hit </span>
<span class="sd">    point. This object hold that information.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="SegmentQueryInfo.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.SegmentQueryInfo.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">shape</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;You shouldn&#39;t need to initialize SegmentQueryInfo objects on your </span>
<span class="sd">        own.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span> <span class="o">=</span> <span class="n">shape</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_t</span> <span class="o">=</span> <span class="n">t</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_n</span> <span class="o">=</span> <span class="n">n</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_start</span> <span class="o">=</span> <span class="n">start</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_end</span> <span class="o">=</span> <span class="n">end</span>
        </div>
    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s">&quot;SegmentQueryInfo(</span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_start</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_end</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">t</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">)</span>
            
    <span class="n">shape</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="k">lambda</span> <span class="bp">self</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_shape</span>
        <span class="p">,</span> <span class="n">doc</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;Shape that was hit&quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="n">t</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="k">lambda</span> <span class="bp">self</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_t</span>
        <span class="p">,</span> <span class="n">doc</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;Distance along query segment, will always be in the range [0, 1]&quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="n">n</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="k">lambda</span> <span class="bp">self</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_n</span>
        <span class="p">,</span> <span class="n">doc</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;Normal of hit surface&quot;&quot;&quot;</span><span class="p">)</span>
        
<div class="viewcode-block" id="SegmentQueryInfo.get_hit_point"><a class="viewcode-back" href="../pymunk.html#pymunk.SegmentQueryInfo.get_hit_point">[docs]</a>    <span class="k">def</span> <span class="nf">get_hit_point</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the hit point in world coordinates where the segment first </span>
<span class="sd">        intersected with the shape</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c">#todo: use ffi function</span>
        <span class="k">return</span> <span class="n">Vec2d</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_start</span><span class="p">)</span><span class="o">.</span><span class="n">interpolate_to</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_end</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">t</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="SegmentQueryInfo.get_hit_distance"><a class="viewcode-back" href="../pymunk.html#pymunk.SegmentQueryInfo.get_hit_distance">[docs]</a>    <span class="k">def</span> <span class="nf">get_hit_distance</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the absolute distance where the segment first hit the shape</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c">#todo: use ffi function</span>
        <span class="k">return</span> <span class="n">Vec2d</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_start</span><span class="p">)</span><span class="o">.</span><span class="n">get_distance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_end</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">t</span>
    
    </div></div>
<div class="viewcode-block" id="moment_for_circle"><a class="viewcode-back" href="../pymunk.html#pymunk.moment_for_circle">[docs]</a><span class="k">def</span> <span class="nf">moment_for_circle</span><span class="p">(</span><span class="n">mass</span><span class="p">,</span> <span class="n">inner_radius</span><span class="p">,</span> <span class="n">outer_radius</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
    <span class="sd">&quot;&quot;&quot;Calculate the moment of inertia for a circle&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpMomentForCircle</span><span class="p">(</span><span class="n">mass</span><span class="p">,</span> <span class="n">inner_radius</span><span class="p">,</span> <span class="n">outer_radius</span><span class="p">,</span> <span class="n">offset</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="moment_for_segment"><a class="viewcode-back" href="../pymunk.html#pymunk.moment_for_segment">[docs]</a><span class="k">def</span> <span class="nf">moment_for_segment</span><span class="p">(</span><span class="n">mass</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Calculate the moment of inertia for a segment&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpMomentForSegment</span><span class="p">(</span><span class="n">mass</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="moment_for_poly"><a class="viewcode-back" href="../pymunk.html#pymunk.moment_for_poly">[docs]</a><span class="k">def</span> <span class="nf">moment_for_poly</span><span class="p">(</span><span class="n">mass</span><span class="p">,</span> <span class="n">vertices</span><span class="p">,</span>  <span class="n">offset</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
    <span class="sd">&quot;&quot;&quot;Calculate the moment of inertia for a polygon&quot;&quot;&quot;</span>
    <span class="n">verts</span> <span class="o">=</span> <span class="p">(</span><span class="n">Vec2d</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">vertices</span><span class="p">))</span>
    <span class="n">verts</span> <span class="o">=</span> <span class="n">verts</span><span class="p">(</span><span class="n">Vec2d</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
    <span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">vertex</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">vertices</span><span class="p">):</span>
        <span class="n">verts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="n">vertex</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">verts</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="n">vertex</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpMomentForPoly</span><span class="p">(</span><span class="n">mass</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">verts</span><span class="p">),</span> <span class="n">verts</span><span class="p">,</span> <span class="n">offset</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="moment_for_box"><a class="viewcode-back" href="../pymunk.html#pymunk.moment_for_box">[docs]</a><span class="k">def</span> <span class="nf">moment_for_box</span><span class="p">(</span><span class="n">mass</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Calculate the momentn of inertia for a box&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpMomentForBox</span><span class="p">(</span><span class="n">mass</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="reset_shapeid_counter"><a class="viewcode-back" href="../pymunk.html#pymunk.reset_shapeid_counter">[docs]</a><span class="k">def</span> <span class="nf">reset_shapeid_counter</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;Reset the internal shape counter</span>
<span class="sd">    </span>
<span class="sd">    pymunk keeps a counter so that every new shape is given a unique hash </span>
<span class="sd">    value to be used in the spatial hash. Because this affects the order in </span>
<span class="sd">    which the collisions are found and handled, you should reset the shape </span>
<span class="sd">    counter every time you populate a space with new shapes. If you don&#39;t, </span>
<span class="sd">    there might be (very) slight differences in the simulation.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">cp</span><span class="o">.</span><span class="n">cpResetShapeIdCounter</span><span class="p">()</span>

    </div>
<div class="viewcode-block" id="Contact"><a class="viewcode-back" href="../pymunk.html#pymunk.Contact">[docs]</a><span class="k">class</span> <span class="nc">Contact</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Contact information&quot;&quot;&quot;</span>
<div class="viewcode-block" id="Contact.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.Contact.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">_contact</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize a Contact object from the Chipmunk equivalent struct</span>
<span class="sd">        </span>
<span class="sd">        .. note:: </span>
<span class="sd">            You should never need to create an instance of this class directly.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_point</span> <span class="o">=</span> <span class="n">_contact</span><span class="o">.</span><span class="n">point</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_normal</span> <span class="o">=</span> <span class="n">_contact</span><span class="o">.</span><span class="n">normal</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_dist</span> <span class="o">=</span> <span class="n">_contact</span><span class="o">.</span><span class="n">dist</span>
        <span class="c">#self._contact = contact</span>
</div>
    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s">&quot;Contact(p: </span><span class="si">%s</span><span class="s">, n: </span><span class="si">%s</span><span class="s">, d: </span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">position</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">normal</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">distance</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_get_position</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_point</span>
    <span class="n">position</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_position</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Contact position&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_normal</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_normal</span>
    <span class="n">normal</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_normal</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Contact normal&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_distance</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dist</span>
    <span class="n">distance</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_distance</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Penetration distance&quot;&quot;&quot;</span><span class="p">)</span>
    

</div>
<div class="viewcode-block" id="Arbiter"><a class="viewcode-back" href="../pymunk.html#pymunk.Arbiter">[docs]</a><span class="k">class</span> <span class="nc">Arbiter</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Arbiters are collision pairs between shapes that are used with the </span>
<span class="sd">    collision callbacks.</span>
<span class="sd">    </span>
<span class="sd">    .. Warning::</span>
<span class="sd">        Because arbiters are handled by the space you should never </span>
<span class="sd">        hold onto a reference to an arbiter as you don&#39;t know when it will be </span>
<span class="sd">        destroyed! Use them within the callback where they are given to you </span>
<span class="sd">        and then forget about them or copy out the information you need from </span>
<span class="sd">        them.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="Arbiter.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.Arbiter.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">_arbiter</span><span class="p">,</span> <span class="n">space</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Initialize an Arbiter object from the Chipmunk equivalent struct </span>
<span class="sd">        and the Space.</span>
<span class="sd">        </span>
<span class="sd">        .. note::</span>
<span class="sd">            You should never need to create an instance of this class directly.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span> <span class="o">=</span> <span class="n">_arbiter</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_arbitercontents</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="o">.</span><span class="n">contents</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_space</span> <span class="o">=</span> <span class="n">space</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_contacts</span> <span class="o">=</span> <span class="bp">None</span> <span class="c"># keep a lazy loaded cache of converted contacts</span>
    </div>
    <span class="k">def</span> <span class="nf">_get_contacts</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">point_set</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpArbiterGetContactPointSet</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contacts</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_contacts</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">point_set</span><span class="o">.</span><span class="n">count</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">contacts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Contact</span><span class="p">(</span><span class="n">point_set</span><span class="o">.</span><span class="n">points</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contacts</span>
    <span class="n">contacts</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_contacts</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Information on the contact points between the objects. Return [`Contact`]&quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_get_shapes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">shapeA_p</span> <span class="o">=</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpShape</span><span class="p">)()</span>
        <span class="n">shapeB_p</span> <span class="o">=</span> <span class="n">ct</span><span class="o">.</span><span class="n">POINTER</span><span class="p">(</span><span class="n">cp</span><span class="o">.</span><span class="n">cpShape</span><span class="p">)()</span>
        
        <span class="n">cpffi</span><span class="o">.</span><span class="n">cpArbiterGetShapes</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="p">,</span> <span class="n">shapeA_p</span><span class="p">,</span> <span class="n">shapeB_p</span><span class="p">)</span>
    
        <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">shapeA_p</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_space</span><span class="o">.</span><span class="n">_get_shape</span><span class="p">(</span><span class="n">shapeB_p</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span>
        
    <span class="n">shapes</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_shapes</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Get the shapes in the order that they were defined in the </span>
<span class="s">        collision handler associated with this arbiter&quot;&quot;&quot;</span><span class="p">)</span>
            
    <span class="k">def</span> <span class="nf">_get_elasticity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">e</span>
    <span class="k">def</span> <span class="nf">_set_elasticity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elasticity</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">e</span> <span class="o">=</span> <span class="n">elasticity</span>
    <span class="n">elasticity</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_elasticity</span><span class="p">,</span> <span class="n">_set_elasticity</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Elasticity&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_friction</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">u</span>
    <span class="k">def</span> <span class="nf">_set_friction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">friction</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">u</span> <span class="o">=</span> <span class="n">friction</span>
    <span class="n">friction</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_friction</span><span class="p">,</span> <span class="n">_set_friction</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Friction&quot;&quot;&quot;</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_get_surface_velocity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">surface_vr</span>
    <span class="n">surface_velocity</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_surface_velocity</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Used for surface_v calculations, implementation may change&quot;&quot;&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_total_impulse</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpArbiterTotalImpulse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="p">)</span>
    <span class="n">total_impulse</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_total_impulse</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Returns the impulse that was applied this step to resolve the </span>
<span class="s">        collision.</span>
<span class="s">        </span>
<span class="s">        This property should only be called from a post-solve, post-step&quot;&quot;&quot;</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_get_total_impulse_with_friction</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpArbiterTotalImpulseWithFriction</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="p">)</span>
    <span class="n">total_impulse_with_friction</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_total_impulse_with_friction</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Returns the impulse with friction that was applied this step to </span>
<span class="s">        resolve the collision.</span>
<span class="s">        </span>
<span class="s">        This property should only be called from a post-solve, post-step&quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_get_total_ke</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpArbiterTotalKE</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="p">)</span>
    <span class="n">total_ke</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_total_ke</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;The amount of energy lost in a collision including static, but </span>
<span class="s">        not dynamic friction.</span>
<span class="s">        </span>
<span class="s">        This property should only be called from a post-solve, post-step&quot;&quot;&quot;</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_get_stamp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">stamp</span>
    <span class="n">stamp</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_stamp</span><span class="p">,</span> 
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Time stamp of the arbiter. (from the space)&quot;&quot;&quot;</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_get_is_first_contact</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="n">cpffi</span><span class="o">.</span><span class="n">cpArbiterIsFirstContact</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_arbiter</span><span class="p">))</span>
    <span class="n">is_first_contact</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">_get_is_first_contact</span><span class="p">,</span>
        <span class="n">doc</span><span class="o">=</span><span class="s">&quot;&quot;&quot;Returns true if this is the first step that an arbiter existed. </span>
<span class="s">        You can use this from preSolve and postSolve to know if a collision </span>
<span class="s">        between two shapes is new without needing to flag a boolean in your </span>
<span class="s">        begin callback.&quot;&quot;&quot;</span><span class="p">)</span>
        
    
    </div>
<div class="viewcode-block" id="BB"><a class="viewcode-back" href="../pymunk.html#pymunk.BB">[docs]</a><span class="k">class</span> <span class="nc">BB</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Simple bounding box class. Stored as left, bottom, right, top values.&quot;&quot;&quot;</span>
<div class="viewcode-block" id="BB.__init__"><a class="viewcode-back" href="../pymunk.html#pymunk.BB.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Create a new instance of a bounding box. Can be created with zero </span>
<span class="sd">        size with bb = BB() or with four args defining left, bottom, right and</span>
<span class="sd">        top: bb = BB(left, bottom, right, top)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_bb</span> <span class="o">=</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpBB</span><span class="p">()</span>
        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_bb</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_bb</span> <span class="o">=</span> <span class="n">cpffi</span><span class="o">.</span><span class="n">cpBBNew</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
            </div>
    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s">&#39;BB(</span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">, </span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">left</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bottom</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">right</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">top</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">left</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">left</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">bottom</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">bottom</span> <span class="ow">and</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">right</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">right</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">top</span> <span class="o">==</span> <span class="n">other</span><span class="o">.</span><span class="n">top</span>
    
    <span class="k">def</span> <span class="nf">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">__eq__</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>
        
<div class="viewcode-block" id="BB.intersects"><a class="viewcode-back" href="../pymunk.html#pymunk.BB.intersects">[docs]</a>    <span class="k">def</span> <span class="nf">intersects</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns true if the bounding boxes intersect&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="n">cpffi</span><span class="o">.</span><span class="n">cpBBIntersects</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">_bb</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="BB.contains"><a class="viewcode-back" href="../pymunk.html#pymunk.BB.contains">[docs]</a>    <span class="k">def</span> <span class="nf">contains</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns true if bb completley contains the other bb&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="n">cpffi</span><span class="o">.</span><span class="n">cpBBContainsBB</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">_bb</span><span class="p">))</span>
        </div>
<div class="viewcode-block" id="BB.contains_vect"><a class="viewcode-back" href="../pymunk.html#pymunk.BB.contains_vect">[docs]</a>    <span class="k">def</span> <span class="nf">contains_vect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns true if this bb contains the vector v&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="n">cpffi</span><span class="o">.</span><span class="n">cpBBContainsVect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span>
        </div>
<div class="viewcode-block" id="BB.merge"><a class="viewcode-back" href="../pymunk.html#pymunk.BB.merge">[docs]</a>    <span class="k">def</span> <span class="nf">merge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the minimal bounding box that contains both this bb and the </span>
<span class="sd">        other bb</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">BB</span><span class="p">(</span><span class="n">cpffi</span><span class="o">.</span><span class="n">cpBBMerge</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">_bb</span><span class="p">))</span>
        </div>
<div class="viewcode-block" id="BB.expand"><a class="viewcode-back" href="../pymunk.html#pymunk.BB.expand">[docs]</a>    <span class="k">def</span> <span class="nf">expand</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the minimal bounding box that contans both this bounding box </span>
<span class="sd">        and the vector v</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">BB</span><span class="p">(</span><span class="n">cpffi</span><span class="o">.</span><span class="n">cpBBExpand</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span>
        </div>
    <span class="n">left</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="k">lambda</span> <span class="bp">self</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="o">.</span><span class="n">l</span><span class="p">)</span>
    <span class="n">bottom</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="k">lambda</span> <span class="bp">self</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="o">.</span><span class="n">b</span><span class="p">)</span>
    <span class="n">right</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="k">lambda</span> <span class="bp">self</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="o">.</span><span class="n">r</span><span class="p">)</span>
    <span class="n">top</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="k">lambda</span> <span class="bp">self</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="o">.</span><span class="n">t</span><span class="p">)</span>
    
<div class="viewcode-block" id="BB.clamp_vect"><a class="viewcode-back" href="../pymunk.html#pymunk.BB.clamp_vect">[docs]</a>    <span class="k">def</span> <span class="nf">clamp_vect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns a copy of the vector v clamped to the bounding box&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">cpffi</span><span class="o">.</span><span class="n">cpBBClampVect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="BB.wrap_vect"><a class="viewcode-back" href="../pymunk.html#pymunk.BB.wrap_vect">[docs]</a>    <span class="k">def</span> <span class="nf">wrap_vect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">v</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Returns a copy of v wrapped to the bounding box.</span>
<span class="sd">        That is, BB(0,0,10,10).wrap_vect((5,5)) == Vec2d(10,10)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">cp</span><span class="o">.</span><span class="n">cpBBWrapVect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bb</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
 
        
<span class="c">#del cp, ct, u</span>
</pre></div></div></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/pymunk_logo_sphinx.png" alt="Logo"/>
            </a></p>
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../readme.html">Readme</a></li>
<li class="toctree-l1"><a class="reference internal" href="../news.html">News</a></li>
<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../pymunk.html">API Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../examples.html">Examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorials.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced.html">Advanced</a></li>
<li class="toctree-l1"><a class="reference external" href="http://code.google.com/p/pymunk/issues/list">Issue Tracker</a></li>
<li class="toctree-l1"><a class="reference external" href="http://code.google.com/p/pymunk/source/checkout">Source Repository</a></li>
<li class="toctree-l1"><a class="reference external" href="http://code.google.com/p/pymunk/downloads/list">Downloads</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../index.html">pymunk 4.0.0 documentation</a> &raquo;</li>
          <li><a href="index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2013, Victor Blomqvist.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>